<?php
/* @var $this ProductController */
/* @var $model Product */
/* @var $form CActiveForm */
?>
<script src="<?php echo Yii::app()->baseUrl . '/ckeditor/ckeditor.js'; ?>"></script>
<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'product-_product-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // See class documentation of CActiveForm for details on this,
        // you need to use the performAjaxValidation()-method described there.
        'enableAjaxValidation' => false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
    ));
    ?>


    <?php echo $form->errorSummary($model); ?>

    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_name'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_name', array('size' => 50, 'maxlength' => 50, 'required' => 'required')); ?>
        <?php echo $form->error($model, 'pr_name'); ?>
    </div>

    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'pr_url', array('size' => 50, 'maxlength' => 200, 'required' => 'required')); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_url', array('size' => 60, 'maxlength' => 200)); ?>
        <?php echo $form->error($model, 'pr_url'); ?>
    </div>

    <div class="clear"></div>

<?php
    $session = new CHttpSession;
    $session->open();
    if ($session['user_salesmart'][1] > 98) {
        ?>


    <div class="clear"></div>
    <?php }?>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'discount'); ?>
    </div>
    <div class="form_right">

        <?php
        
        echo CHtml::dropDownList('loai', '', array('prompt' => '----- Chọn loại -----','999' => 'Giảm giá', '1000' => 'New', '1001' => 'Quà tặng')
                , array(
            'ajax' => array(
                'type' => 'POST', //request type
                'url' => CController::createUrl('manager/dynamicvalueloai'), //url to call.
                'update' => '#hinhthuc', //selector to update
                'data' => array('id' => 'js:this.value'),
        )));

        // echo $form->textField($model, 'discount', array( 'style' => 'width:80px;')); 
        ?>


        <div id="hinhthuc">
            <?php
            if (!empty($model)) {
                if($model->discount<1000){
                echo $form->textField($model, 'discount', array( 'style' => 'width:80px;'));
                }
            }
            ?>
        </div>

    </div>
    <div class="clear"></div>
    <div class="form_left">
<?php echo $form->labelEx($model, 'asia_name'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'asia_name', array('size' => 60, 'maxlength' => 200, 'required' => 'required')); ?>
<?php echo $form->error($model, 'asia_name'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
<?php echo $form->labelEx($model, 'avatar'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->fileField($model, 'avatar', array('size' => 40, 'maxlength' => 50)); ?>
<?php echo $form->error($model, 'avatar'); ?>
    </div>

    <div class="clear"></div>


    <div class="form_left">
<?php echo $form->labelEx($model, 'cate_id'); ?>
    </div>
    <div class="form_right">
        <?php
        $category_ = Category::model()->findAll();
        foreach ($category_ as $item) {
            if ($item->parent > 0) {
                $item->catename = '   + ' . $item->catename;
            }
        }

        $list_ = CHtml::listData($category_, 'cateid', 'catename');
        echo $form->dropDownList($model, 'cate_id', $list_);
        ?>

<?php echo $form->error($model, 'cate_id'); ?>
    </div>


    <div class="clear"></div>


    <div class="form_left">
<?php echo $form->labelEx($model, 'ctiID'); ?>
    </div>
    <div class="form_right">
        <?php
        $models = City::model()->findAll();
        $list = CHtml::listData($models, 'cityID', 'cityName');
        echo $form->dropDownList($model, 'ctiID', $list);
        ?>
<?php echo $form->error($model, 'ctiID'); ?>
    </div>


    <div class="clear"></div>


    <div class="form_left">
<?php echo $form->labelEx($model, 'pr_description'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textArea($model, 'pr_description', array('size' => 70, 'maxlength' => 400)); ?>
<?php echo $form->error($model, 'pr_description'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
<?php echo $form->labelEx($model, 'pr_meta'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textArea($model, 'pr_meta', array('size' => 70, 'maxlength' => 250)); ?>
<?php echo $form->error($model, 'pr_meta'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
<?php echo $form->labelEx($model, 'pr_stardate'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_stardate', array('class' => 'easyui-datebox', 'data-options' => 'formatter:myformatter,parser:myparser')); ?>
<?php echo $form->error($model, 'pr_stardate'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
<?php echo $form->labelEx($model, 'pr_enddate'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textField($model, 'pr_enddate', array('class' => 'easyui-datebox', 'data-options' => 'formatter:myformatter,parser:myparser')); ?>
<?php echo $form->error($model, 'pr_enddate'); ?>
    </div>
    <div class="clear"></div>
    <div class="clear"></div>
    <?php
    $session = new CHttpSession;
    $session->open();
    if ($session['user_salesmart'][1] > 98) {
        ?>
        <div class="form_left">
    <?php echo $form->labelEx($model, 'flag'); ?>
        </div>
        <div class="form_right">

    <?php echo $form->dropDownList($model, 'flag', array('0' => 'Đang ẩn', '1' => 'Đang hiện', '2' => 'Hủy')); ?>
        </div>
        <div class="clear"></div>
        <?php } ?>
    <div class="form_left">
<?php echo $form->labelEx($model, 'pr_content'); ?>
    </div>
    <div class="form_right">
        <?php echo $form->textArea($model, 'pr_content', array('id' => 'editor1')); ?>

<?php echo $form->error($model, 'pr_content'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">.</div>
</div>
<div class="form_right">
<?php echo CHtml::submitButton('Cập nhật'); ?>
</div>

<?php $this->endWidget(); ?>
<script type="text/javascript">
    CKEDITOR.replace('editor1', {
        filebrowserBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=files',
        filebrowserImageBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=images',
        filebrowserFlashBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=flash',
        filebrowserUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=files',
        filebrowserImageUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=images',
        filebrowserFlashUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=flash'
    });
</script>
<script type="text/javascript">
    function myformatter(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
    }
    function myparser(s) {
        if (!s)
            return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0], 10);
        var m = parseInt(ss[1], 10);
        var d = parseInt(ss[2], 10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
            return new Date(y, m - 1, d);
        } else {
            return new Date();
        }
    }
</script>
</div><!-- form -->
